<?php 
namespace app\ucenter\controller;
use think\Input;
use think\Controller;
use app\ucenter\model\UcenterUsers as User;
class Member extends Controller{
	/*获取用户id*/
   public function getUid($email=null){
	   	 $uid = User::checkUidForEmail($email);
	   	 if($uid > 0){
	   	  	return ['code'=>0,'msg'=>lang('Success'),'uid'=>$uid];
	   	 }
	   	 return ['code'=>-1,'msg'=>lang('Fail'),'uid'=>0];
   }
   /*获取用户信息*/
   public function getUser($parameter=null){
	   	if(is_email($parameter)){
	   	 	$user = User::checkUserForEmail($parameter);
	   	}else{
	   	 	$user = User::checkUserForUid($parameter);
	   	}
	   	if($user){
	   	 	return ['code'=>0,'msg'=>'Success','data'=>$user];
	   	}
	   	return ['code'=>-1,'msg'=>lang('Fail'),'data'=>[]];
   }
   /*判断用户是否可以登录*/
   public function checkLogin($email=null,$password=null){
   	   //$token = $this->request->header();
   	   $result = User::checkLogin($email,$password);
   	   if($result['code'] == 0){
   	   		return ['code'=>0,'msg'=>lang('Success'),'data'=>$result['data']];
   	   }
   	   return ['code'=>-1,'msg'=>$result['error'],'data'=>[]];
   }
   /*修改用户*/
   public function editUser(){
      if($this->request->isPost()){
        $data = $this->request->post();
        if($uid = User::checkUidForEmail($data['condition'])){
            $result = User::editUser($data,$uid);
        }else{
            $result = User::register($data);
        }
        if($result['code'] == 0){
          return ['code'=>0,'msg'=>lang('Success')];
         } 
      }
        
      return ['code'=>-1,'msg'=>$result['error']];
   }
   /*注册*/
   public function register(){
   	  $data = $this->request->post();
   	  $result = User::register($data);
   	  if($result['code'] == 0){
	   	    return ['code'=>0,'msg'=>lang('Success')];
	   }
   	   return ['code'=>-1,'msg'=>$result['error']];
   }
   /*同步用户信息*/
   public function syncUser(){
      if($this->request->isPost()){
        $data = $this->request->post();
        $result = User::syncUser($data);
        if($result['code'] == 0){
          return ['code'=>0,'msg'=>lang('Success')];
         } 
      }
   	  
   	return ['code'=>-1,'msg'=>$result['error']];
   }
   /*修改密码*/
   public function editPassword(){
      if($this->request->isPost()){
         $data = $this->request->post();
         return User::editPassword($data);
      }
      return ['code'=>-1,'msg'=>lang('fail')];
   }
   /*删除用户*/
   public function delete($email){
      $result = User::delUser($email);
      if($result){
        return ['code'=>0,'msg'=>lang('success')];
      }
      return ['code'=>-1,'msg'=>lang('fail')];
   }
}
?>